#ifndef __ARGPROC_H
#define __ARGPROC_H

#include <stdarg.h>
#include <glib.h>


/*
 *  build argument and value pairs into vectors, return numbers,
 *vectors are return via @argv, if @argv is not NULL and @*argc is not
 *0, new argc will be appened to @argv. use the g_strfreev to free the
 *returned @argv, call this function with key and value string pairs
 *with an NULL indicating the end.
 *
 *  NOTE: append argument to @argv, the old @argv is deep duplicated,
 *and the pointer to the vector is lost, save is before append to it
 */
gboolean     build_arg(gint *argc, gchar ***argv, ...);


/*
 *all key values pairs(KEY=VALUE) are store in the string @*args
 *allocated via g_new consecutively, with double NULL indicating the
 *end, if @args is not NULL, @len will be read as the length of the
 *memory of @*args, the funtion will parse @*args, and append new
 *value pairs to the end.
 *
 *NOTE: @*args can be moved and NULL values are ignored.
 */
gboolean     build_arg_str(gint len, gchar **args, ...);

/*
 *return string must be freed while not used
 */
gchar       *parse_arg(const gchar *key, gint argc, gchar **argv);
gboolean     parse_arg_integer(const gchar *key, gint *val, gint argc, gchar **argv);
gboolean     parse_arg_float(const gchar *key, gfloat *val, gint argc, gchar **argv);
gboolean     parse_arg_string(const gchar *key, gchar **val, gint argc, gchar **argv);


gchar       *parse_arg_str(const gchar *key, const gchar *args);
gboolean     parse_arg_str_integer(const gchar *key, gint *val, const gchar *args);
gboolean     parse_arg_str_float(const gchar *key, gfloat *val, const gchar *args);
gboolean     parse_arg_str_string(const gchar *key, gchar **val, const gchar *args);

/* convertion between cevtor args and string args */
gboolean    build_arg_to_str(gint argc, gchar **argv, gchar **args);
gboolean    build_arg_from_str(gint *argc, gchar ***argv, const gchar *args);

#endif /* __ARGPROC_H */

